package com.shuoyue.ycgk.ui.papergroups;

import android.os.Bundle;
import android.text.TextUtils;
import android.widget.TextView;

import com.google.android.material.tabs.TabLayout;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.shuoyue.ycgk.R;
import com.shuoyue.ycgk.appcatch.SPUtils;
import com.shuoyue.ycgk.base.BaseMvpActivity;
import com.shuoyue.ycgk.base.BaseMvpFragment;
import com.shuoyue.ycgk.base.baseadapter.IndexFragmentStateAdapter;
import com.shuoyue.ycgk.entity.Type;
import com.shuoyue.ycgk.ui.common.CommonModuleContract;
import com.shuoyue.ycgk.views.viewpager_scroll.SuperViewPager;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

public abstract class BasePaperGroupActivity extends BaseMvpActivity<CommonModuleContract.Presenter>
        implements CommonModuleContract.View {

    @BindView(R.id.page_title)
    protected TextView pageTitle;
    @BindView(R.id.tab_layout)
    protected TabLayout tabLayout;
    @BindView(R.id.view_pager)
    protected SuperViewPager viewPager;
    @BindView(R.id.refreshlayout)
    protected SmartRefreshLayout refreshlayout;

    protected IndexFragmentStateAdapter indexFragmentAdapter;
    protected List<BaseMvpFragment> fragmentMainItems;
    protected String selectBaseType;

    protected Type topType;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_paper_set;
    }

    @Override
    protected void initView() {
        pageTitle.setText("题库");
        refreshlayout.setEnableLoadMore(false);
        refreshlayout.setOnRefreshListener(refreshLayout -> {
            mPresenter.getBaseModels(1);
            refreshLayout.finishRefresh(2000);
        });
    }

    @Override
    public void initData() {
        mPresenter = new CommonModuleContract.Presenter();
        mPresenter.attachView(this);
        mPresenter.getBaseModels(1);
    }


    @OnClick(R.id.back)
    public void onViewClicked() {
        finish();
    }

    @Override
    public void setBaseType(List<Type> baseTypes) {
        if (TextUtils.isEmpty(selectBaseType)) {
            selectBaseType = SPUtils.getLastSelectMoudle(mContext);
        }
        for (Type item : baseTypes) {
            if (item.getName().equals(selectBaseType)) {
                topType = item;
                mPresenter.getChildType(item.getId());
                break;
            }
        }
    }

}
